package com.kzx.blog.controller;

import com.kzx.blog.service.IFile;
import com.kzx.blog.service.IUser;
import com.kzx.blog.util.ParseHttp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @author kongz
 * @version 1.0 2021/12/9 17:33
 * @description 文件接口
 */
@RestController
@RequestMapping("/file")
@Api(value = "FileController", tags = {"文件接口"})
public class FileController {

    private final IFile iFile;

    private final IUser iUser;

    public FileController(IFile iFile, IUser iUser) {
        this.iFile = iFile;
        this.iUser = iUser;
    }

    @ApiOperation("文件上传")
    @PostMapping("/upload")
    public String upload(@RequestPart("file") MultipartFile file, HttpServletRequest request) {
        String token = ParseHttp.getHttpAccessToken(request);
        iUser.getToken(token);
        return iFile.upload(file);
    }

}
